<template>
  <div class="walk-to-earn-page">
    <!-- 顶部左侧图标 -->
    <div class="side-icons">
      <div @click="goToMessageCenter" class="icon-wrapper message-icon">
        <div v-show="unreadCount > 0" class="notification-badge">
          <span>{{ unreadCount }}</span>
        </div>
      </div>
      <div class="icon-wrapper rules-icon"></div>
    </div>
    <!-- 顶部右侧信息 -->
    <div class="top-right-info">
      <div class="balance-display ">
        <div class="coin-icon"></div>
        <span class="coin-amount">{{ goldCoins }}</span>
      </div>
      <div class="check-in-status" @click="toggleCheckIn">
        <div class="check-in-icon">
          <div v-if="!isCheckedIn" class="check-in-dot"></div>
        </div>
        <span class="check-in-text">{{ isCheckedIn ? '已签到' : '未签到' }}</span>
      </div>
    </div>
    <!-- 上下浮动动画 -->
    <div class="task-grid">
      <div v-for="task in tasks" :key="task.id" :class="['task-item', `item-position${task.id}`]"
        class="float-animation" :style="{ animationDelay: `${task.id * 0.2}s` }">
        <span class="task-title">{{ task.title }}</span>
        <div :class="task.isSpecial ? 'task-icon-yellow' : 'task-icon'"></div>
      </div>
    </div>
    <!-- 今日步数 -->
    <div class="steps-background-shape">
      <p class="steps-label">今日步数</p>
      <p class="steps-count">2748</p>
      <p class="steps-reset-info">每日24:00自动清零</p>
    </div>
    <div class="action-button-container">
      <div class="character-container">
        <!-- 奔跑的人物 -->
        <div class="character character-left"></div>
        <div class="character character-right"></div>
      </div>
      <!-- 底部瓜分现金按钮 -->
      <button class="action-button">瓜分888现金</button>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
import { storeToRefs } from 'pinia'
import { useGoldCoinStore } from '@/stores/goldCoins'
const goldCoinStore = useGoldCoinStore()

const { goldCoins } = storeToRefs(goldCoinStore)

import { useMessageStore } from '@/stores/message';
// 使用 store
const messageStore = useMessageStore();

// 签到状态变量，默认为已签到
const { allActivityMessages, allOrderMessages, isCheckedIn } = storeToRefs(messageStore)
// 计算未读消息数量
const unreadCount = computed(() => {
  return allActivityMessages.value.filter(msg => !msg.read).length +
    allOrderMessages.value.filter(msg => !msg.read).length
})

// 任务项数据
import { TASKS } from '../config';
const tasks = ref(TASKS);

// 切换签到状态的函数
const toggleCheckIn = () => {
  if (!isCheckedIn.value) {
    isCheckedIn.value = !isCheckedIn.value
  }
}
// 跳转到消息中心
const goToMessageCenter = () => {
  router.push({ name: 'MessageCenter' })
}
</script>
<style lang="scss" scoped>
.walk-to-earn-page {
  height: 48.9vh;
  background-image: url('@/assets/image/bg@2x.webp');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center;

  .side-icons {
    position: absolute;
    top: 16px;
    left: 10px;

    .icon-wrapper {
      width: 29px;
      height: 37px;
      background-size: 100% 100%;
      background-repeat: no-repeat;
      background-position: center;

      .notification-badge {
        position: absolute;
        top: -5px;
        right: -5px;
        width: 12px;
        height: 12px;
        background: #FF876A;
        border: 1px solid #FFFFFF;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;

        span {
          font-size: 10px;
          color: #FFFFFF;
        }
      }
    }

    .message-icon {
      position: relative;
      background-image: url('@/assets/image/编组 13@2x.webp');
      margin-bottom: 9px;
    }

    .rules-icon {
      background-image: url('@/assets/image/编组 13备份@2x.webp');
    }
  }

  .top-right-info {
    position: absolute;
    top: 21px;
    right: 0;

    .balance-display,
    .check-in-status {
      box-sizing:border-box;
      width: 68px;
      height: 31px;
      background-color: rgba(222, 223, 220, 0.7);
      border-radius: 14px 0px 0px 14px;
      margin-bottom: 12px;
      display: flex;
      align-items: center;
      padding-left: 5px;

      .coin-icon,
      .check-in-icon {
        width: 25px;
        height: 25px;
        background-size: 100% 100%;
        background-repeat: no-repeat;
        background-position: center;
        margin-right: 2px;

      }

      .coin-icon {
        background-image: url('@/assets/image/编组 3@2x(1).webp');
      }

      .coin-amount {
        font-size: 17px;
        color: #027C64;
      }

      .check-in-icon {
        background-image: url('@/assets/image/编组 3@2x.webp');
        position: relative;

        .check-in-dot {
          position: absolute;
          top: 0;
          right: 0;
          width: 7px;
          height: 7px;
          background-color: #FF3B30;
          border-radius: 50%;
        }
      }

      .check-in-text {
        font-size: 11px;
        color: #027C64;
      }
    }

  }

  .steps-background-shape {
    position: absolute;
    top: 21vh;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 19.45vh;
    height: 19.45vh;
    padding-top: 21px;
    border-radius: 50%;
    background: linear-gradient(0, rgba(255, 255, 255, 0) 0%, #FFFFFF 100%);

    .steps-label {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 12px;
      color: #999999;
      line-height: 12px;
      text-align: left;
      font-style: normal;
    }

    .steps-count {
      font-family: DINCondensed, DINCondensed;
      font-weight: 600;
      font-size: 37px;
      color: #084F3E;
      line-height: 57px;
      text-align: left;
      font-style: normal;
      // 字体模糊处理
      text-shadow: 0px 0px 10px rgba(1, 37, 22, 0.2);
    }

    .steps-reset-info {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 12px;
      color: #999999;
      line-height: 12px;
      text-align: left;
      font-style: normal;
    }
  }

  .action-button-container {
    position: absolute;
    top: 28.60vh;
    left: 50%;
    transform: translateX(-50%);

    .character-container {
      z-index: -1;
      position: relative;
      top: 4px;
      display: flex;
      justify-content: space-between;
      padding: 0 30px;
      box-sizing: border-box;
      width: 100%;

      .character {
        width: 34px;
        height: 7.3vh;
        background-size: 100% 100%;
        background-repeat: no-repeat;
        background-position: center;
      }

      .character-left {
        background-image: url('@/assets/image/boy@2x.webp');
      }

      .character-right {
        background-image: url('@/assets/image/girl@2x.webp');
      }
    }


    .action-button {
      box-sizing:content-box;
      border: none;
      width: 234px;
      height: 5.20vh;
      background: linear-gradient(0deg, #FA5721 0%, #FFA901 100%);
      box-shadow: 0px 5px 21px 0px rgba(222, 223, 220, 0.8), inset 0px -2px 4px 0px rgba(247, 181, 0, 0.8);
      border-radius: 26px;
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 18px;
      color: #FFFFFF;
      font-style: normal;
      text-align: center;
    }
  }

  .task-grid {
    .task-item {
      z-index: 10;
      .task-title {
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        font-size: 11px;
        color: #105B50;
        line-height: 11px;
        text-align: center;
        font-style: normal;
      }

      .task-icon,
      .task-icon-yellow {
        width: 45px;
        height: 45px;
        background-size: 100% 100%;
        background-repeat: no-repeat;
        background-position: center;
      }

      .task-icon {
        background-image: url('@/assets/image/编组 4备份 6@2x(1).webp');
      }

      .task-icon-yellow {
        background-image: url('@/assets/image/编组 4备份 6@2x.webp');
      }
    }

    .item-position1 {
      position: absolute;
      top: 15vh;
      left: 38px;
    }

    .item-position2 {
      position: absolute;
      top: 11vh;
      left: 106px;
    }

    .item-position3 {
      position: absolute;
      top: 11.7vh;
      left: 172px;
    }

    .item-position4 {
      position: absolute;
      top: 10.85vh;
      left: 239px;
    }

    .item-position5 {
      position: absolute;
      top: 15.15vh;
      left: 306px;
    }

    // 上下浮动动画
    .float-animation {
      animation: float 3s ease-in-out infinite;
      transform-origin: center;
    }

    @keyframes float {
      0% {
        transform: translateY(0px);
      }

      50% {
        transform: translateY(-10px);
      }

      100% {
        transform: translateY(0px);
      }
    }
  }

}
</style>
